home *** CD-ROM | disk | FTP | other *** search
/ Clickx 115 / Clickx 115.iso / software / tools / windows / tails-i386-0.16.iso / live / filesystem.squashfs / etc / vmware-tools / suspend-vm-default < prev    next >
Encoding:
Text File  |  2010-12-19  |  3.5 KB  |  124 lines

  1. #!/bin/sh
  2. ##########################################################
  3. # Copyright (C) 2001-2008 VMware, Inc. All rights reserved.
  4. #
  5. # This program is free software; you can redistribute it and/or modify it
  6. # under the terms of the GNU Lesser General Public License as published
  7. # by the Free Software Foundation version 2.1 and no later version.
  8. #
  9. # This program is distributed in the hope that it will be useful, but
  10. # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  11. # or FITNESS FOR A PARTICULAR PURPOSE.  See the Lesser GNU General Public
  12. # License for more details.
  13. #
  14. # You should have received a copy of the GNU Lesser General Public License
  15. # along with this program; if not, write to the Free Software Foundation, Inc.,
  16. # 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA.
  17. #
  18. ##########################################################
  19.  
  20. ##########################################################################
  21. # DO NOT modify this file directly as it will be overwritten the next
  22. # time the VMware Tools are installed.
  23. ##########################################################################
  24.  
  25. echo `date` ": Executing '$0'"
  26. echo
  27.  
  28. find_networking_script() {
  29.     local script="error"
  30.     for dir in "/etc/init.d" "/sbin/init.d" "/etc" "/etc/rc.d" ; do
  31.         if [ -d "$dir/rc0.d" ] &&
  32.         [ -d "$dir/rc1.d" ] &&
  33.         [ -d "$dir/rc2.d" ] &&
  34.         [ -d "$dir/rc3.d" ] &&
  35.         [ -d "$dir/rc4.d" ] &&
  36.         [ -d "$dir/rc5.d" ] &&
  37.         [ -d "$dir/rc6.d" ]; then
  38.  
  39.         # Now find the appropriate networking script.
  40.         if [ -d "$dir/init.d" ]; then
  41.         if [ -x "$dir/init.d/network" ]; then
  42.             script="$dir/init.d/network"
  43.         elif [ -x "$dir/init.d/networking" ]; then
  44.             script="$dir/init.d/networking"
  45.         fi
  46.         else
  47.         if [ -x "$dir/network" ]; then
  48.             script="$dir/network"
  49.         elif [ -x "$dir/networking" ]; then
  50.             script="$dir/networking"
  51.         fi
  52.         fi
  53.         fi
  54.     done
  55.  
  56.     echo "$script"
  57. }
  58.  
  59. save_active_NIC_list() {
  60.     ifconfig_path=`which ifconfig 2>/dev/null`
  61.     if [ $? ]; then
  62.        "$ifconfig_path" | grep '^[^[:space:]]' | awk '{ print $1 }' > /var/run/vmware-active-nics
  63.     fi
  64. }
  65.  
  66.  
  67. #
  68. # tranquilizeNetworkManager --
  69. #
  70. #    Put the NetworkManager daemon to sleep (maybe).
  71. #
  72. #    See http://projects.gnome.org/NetworkManager/developers/spec.html .
  73. #
  74. # Results:
  75. #    Sleep(true) request is sent to the NetworkManager D-Bus interface.
  76. #
  77. # Side effects:
  78. #    None.
  79. #
  80.  
  81. tranquilizeNetworkManager() {
  82.    # `which' may be a bit noisy, so we'll shush it.
  83.    dbusSend=`which dbus-send 2>/dev/null`
  84.    if [ $? -eq 0 ]; then
  85.       # NetworkManager 0.6
  86.       $dbusSend --system --dest=org.freedesktop.NetworkManager          \
  87.          /org/freedesktop/NetworkManager                                \
  88.          org.freedesktop.NetworkManager.sleep
  89.       # NetworkManager 0.7.0
  90.       $dbusSend --system --dest=org.freedesktop.NetworkManager          \
  91.          /org/freedesktop/NetworkManager                                \
  92.          org.freedesktop.NetworkManager.Sleep boolean:true
  93.    fi
  94. }
  95.  
  96.  
  97. #
  98. # main
  99. #
  100.  
  101. scriptsdir="`dirname $0`/scripts/`basename $0`.d"
  102. if [ -d "$scriptsdir" ]; then
  103.    for scriptfile in "$scriptsdir"/*; do
  104.       [ -x "$scriptfile" ] && "$scriptfile" suspend-vm
  105.    done
  106. fi
  107.  
  108. save_active_NIC_list
  109.  
  110. network=`find_networking_script`
  111. if [ "$network" != "error" ]; then
  112.    "$network" stop
  113.    # If the network is down, this may fail but that's not a good reason
  114.    # to prevent the suspend.
  115.    status=0
  116. else
  117.    echo "networking script not found"
  118.    status=1
  119. fi
  120.  
  121. tranquilizeNetworkManager
  122.  
  123. exit "$status"
  124.